package user

import org.springframework.cloud.contract.spec.Contract

[Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/users/ids/[\\w,]+')),
                producer('/api/users/ids/1'))

    }
    response {
        status 200
        body("""
          [{
              "id": 1,
              "username": "zhang",
              "email": "zhang@qq.com",
              "mobilePhone": "12345678901",
              "roles": [2]
          }]
        """)
        bodyMatchers {
            jsonPath('$[*]', byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].username', byRegex(onlyAlphaUnicode()))
            jsonPath('$[*].email', byRegex(email()))
            jsonPath('$[*].mobilePhone', byRegex(number()))
            jsonPath('$[*].roles', byType { minOccurrence(0) })

        }
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
},
Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/api/users/ids/[\\w,]+')),
                producer('/api/users/ids/2'))

    }
    response {
        status 200
        body("""
          [{
              "id": 2,
              "username": "wang",
              "password": "passwordstring",
              "email": "wang@qq.com",
              "mobilePhone": "12345678902",
              "createDate":"1539297039000",
              "roles": [2,9]
          }]
        """)
        bodyMatchers {
            jsonPath('$[*]', byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].username', byRegex(onlyAlphaUnicode()))
            jsonPath('$[*].email', byRegex(email()))
            jsonPath('$[*].mobilePhone', byRegex(number()))
            jsonPath('$[*].roles', byType { minOccurrence(0) })

        }
        headers {
            header('Content-Type': 'application/json;charset=UTF-8')
        }
    }
}
]
